﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PccCommonForC;

public partial class Manager_PrivateInfo_ChangeEmail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["AdminUserID"] == null)
        {
            Response.Write("<script language=javascript>alert('Time is out.');window.open('../Default.aspx','_top');</script>");
            return;
        }
        Ajax.Utility.RegisterTypeForAjax(typeof(Manager_PrivateInfo_ChangeEmail));

        if (!IsPostBack)
            BindData();
    }

    private void BindData()
    {
        clsWebShop cls = new clsWebShop();

        DataTable dt = cls.Get_UserByUserIDNoneProc(Session["AdminUserID"].ToString()).Tables[0];
        if (dt.Rows.Count > 0)
        {
           
            txtEmail.Text = dt.Rows[0]["Email"].ToString();

        }
    }


    protected void btnAdd_Click(object sender, EventArgs e)
    {
        PccMsg msg = new PccMsg();
        clsCommon clsCom = new clsCommon();

        msg.CreateFirstNode("UserID", Session["AdminUserID"].ToString());
        msg.CreateFirstNode("Email", txtEmail.Text);

        msg.CreateFirstNode("Status", "");
        msg.CreateFirstNode("UpdID", "0");

        clsWebShop cls = new clsWebShop();
        cls.Upd_shr_User_Email(msg.GetXmlStr.ToString());
        ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script> alert('Dữ liệu đã cập nhật thành công');</script>");

    }
    [Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.ReadWrite)]
    public string AjaxCheckEmail(string value)
    {
        string flag = "no";
        clsWebShop cls = new clsWebShop();
        DataTable dt = new DataTable();
        PccMsg msg = new PccMsg();
        msg.CreateFirstNode("Email", value.Trim());
        dt = cls.Get_shr_UserByUserEmail(msg.GetXmlStr.ToString()).Tables[0];
        if (dt.Rows.Count > 0)
            flag = "yes";
        return flag;
    }

}
